package com.starinside.wp.controller.action;


import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;

/**
 * Created by wyf on 2017/12/1.
 */
public class ActionTool {

    public static String getParameterNames(HttpServletRequest request){
        String parameter="";
        try {
            Enumeration paramNames = request.getParameterNames();
            while (paramNames.hasMoreElements()) {
                String paramName = (String) paramNames.nextElement();
                if (!"code".equals(paramName)&&!"state".equals(paramName)){
                    String[] paramValues = request.getParameterValues(paramName);
                    if (paramValues.length == 1) {
                        String paramValue = paramValues[0];
//                        if (paramName.equals("redirect")){
//                            paramValue= URLEncoder.encode(paramValue);
//                        }
                        if (paramValue.length() != 0) {
                            parameter=parameter+"&"+paramName+"="+paramValue;
                        }
                    }
                }
            }
            if (parameter.length()>0){
                parameter=parameter.substring(1);
            }
        }catch (Exception e){
            e.printStackTrace();
            return "";
        }
        return parameter;
    }

}
